import time


def fib(n):
    index = 0
    a = 0
    b = 1

    while index < n:
        sleep = yield b
        print('等待%s秒' % sleep)
        time.sleep(sleep)
        a, b = b, a + b
        index += 1


fib = fib(20)
print(fib.send(None))  # 效果等同于print(next(fib))
print(fib.send(2))
print(fib.send(2))
print(fib.send(2))
print(fib.send(2))
